using System;
using UnityEngine;

namespace BCW.Friends
{
	public class FriendsUIChatMessage : MonoBehaviour
	{
		public UIWidget container;

		public UIWidget holder;

		public UILabel messageText;

		public UILabel messageTime;

		public GameObject messageSending;

		public UISprite myMessageBG;

		public UISprite otherMessageBG;

		public bool isMine;

		public long messageId;

		public FriendsUIChatMessage SetMessageUI(bool isMine, string text, double time, long Id = 0)
		{
			this.isMine = isMine;
			messageText.text = text;
			messageId = Id;
			if (time == 0.0)
			{
				messageSending.gameObject.SetActive(true);
				messageTime.gameObject.SetActive(false);
			}
			else
			{
				messageSending.gameObject.SetActive(false);
				messageTime.gameObject.SetActive(true);
				messageTime.text = SetTime(time);
			}
			if (isMine)
			{
				container.pivot = UIWidget.Pivot.Right;
				holder.pivot = UIWidget.Pivot.Right;
				holder.transform.localPosition = new Vector3(-15f, 0f, 0f);
				messageTime.pivot = UIWidget.Pivot.Left;
				messageTime.alignment = NGUIText.Alignment.Left;
				myMessageBG.flip = UIBasicSprite.Flip.Nothing;
				myMessageBG.gameObject.SetActive(true);
				otherMessageBG.gameObject.SetActive(false);
			}
			else
			{
				container.pivot = UIWidget.Pivot.Left;
				holder.pivot = UIWidget.Pivot.Left;
				holder.transform.localPosition = new Vector3(15f, 0f, 0f);
				messageTime.pivot = UIWidget.Pivot.Left;
				messageTime.alignment = NGUIText.Alignment.Left;
				otherMessageBG.flip = UIBasicSprite.Flip.Nothing;
				myMessageBG.gameObject.SetActive(false);
				otherMessageBG.gameObject.SetActive(true);
			}
			return this;
		}

		private string SetTime(double timeStemp)
		{
			return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(timeStemp).ToLocalTime().ToString();
		}
	}
}
